package org.deadline.model.config;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.baseapp.BaseEntity;
import org.deadline.model.user.Person;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class JobTitle extends BaseEntity  implements Serializable {

    @Size(min = 3, max = 100)
    private String jobCode;

    @NotNull
    @Size(min = 3, max = 100)
    private String jobName;

    @ManyToOne
    private Industry industry;

    @ManyToOne
    private Person createdBy;

    @Id
   	@Column(name="id",unique=true,nullable=false)
   	@SequenceGenerator(name="job_title_seq_gen",sequenceName="job_title_seq")
   	@GeneratedValue(generator="job_title_seq_gen",strategy=GenerationType.TABLE)
   	@Generated(GenerationTime.INSERT)
   	private Long id;

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	private static final long serialVersionUID = 1L;

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static JobTitle fromJsonToJobTitle(String json) {
        return new JSONDeserializer<JobTitle>().use(null, JobTitle.class).deserialize(json);
    }

	public static String toJsonArray(Collection<JobTitle> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<JobTitle> fromJsonArrayToJobTitles(String json) {
        return new JSONDeserializer<List<JobTitle>>().use(null, ArrayList.class).use("values", JobTitle.class).deserialize(json);
    }

	public String getJobCode() {
        return this.jobCode;
    }

	public void setJobCode(String jobCode) {
        this.jobCode = jobCode;
    }

	public String getJobName() {
        return this.jobName;
    }

	public void setJobName(String jobName) {
        this.jobName = jobName;
    }

	public Industry getIndustry() {
        return this.industry;
    }

	public void setIndustry(Industry industry) {
        this.industry = industry;
    }

	public Person getCreatedBy() {
        return this.createdBy;
    }

	public void setCreatedBy(Person createdBy) {
        this.createdBy = createdBy;
    }

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	
}
